package com.haiwei.poi.common;

import java.security.SecureRandom;
import java.util.Random;

/**
 * 随机数.
 */
public class HaiweiRandomNumUtil {


    private static final String SYMBOLS = "0123456789"; // 数字

    private static final Random RANDOM = new SecureRandom();


    /**
     * 6位数字验证码
     */
    public static String getNonce_str(int x) {

        // 如果需要4位，那 new char[4] 即可，其他位数同理可得
        char[] nonceChars = new char[x];

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }

        return new String(nonceChars);
    }


    /**
     * 获取图形验证码的值
     * @param x 位数
     * @return string
     */
    public static String getCaptcha_str(int x){
        String str = "";
        char[] ch = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
            'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        Random random = new Random();
        for (int i = 0; i <x; i++){
            char num = ch[random.nextInt(ch.length)];
            str += num;
        }
        return str;
    }





}
